//
//  GuideCollectionVC.m
//  International_Hospital
//
//  Created by 统杰李 on 16/7/11.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "GuideCollectionVC.h"
#import "GuideCell.h"

@interface GuideCollectionVC ()

@property (nonatomic, strong)NSArray *imageArray;

@end

@implementation GuideCollectionVC

#pragma mark
#pragma mark - 懒加载图片
- (NSArray *)imageArray{
    
    if (!_imageArray) {
        
        _imageArray = @[@"1",@"2",@"3",@"4"];
        
    }
    
    return _imageArray;
    
}

static NSString * const reuseIdentifier = @"Cell";

#pragma mark
#pragma mark - 重写init方法
- (instancetype)init{
    //创建流水布局
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    flowLayout.itemSize = [UIScreen mainScreen].bounds.size;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
    
    return [super initWithCollectionViewLayout:flowLayout];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置滚动条
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    self.collectionView.pagingEnabled = YES;
    
    self.collectionView.bounces = NO;
    
    //注册cell
    [self.collectionView registerClass:[GuideCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
}

#pragma mark
#pragma mark - 数据源方法 和 代理方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    return 1;
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 4;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    GuideCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    NSString *imageName = self.imageArray[indexPath.item];
    
    // 最后一个cell显示按钮,其他的隐藏
    if (indexPath.item == self.imageArray.count - 1) {
        cell.startButton.hidden = NO;
        cell.pageControl.hidden = YES;
    } else {
        
        cell.startButton.hidden = YES;
        cell.pageControl.hidden = NO;
    }
    
    cell.pageControl.currentPage = indexPath.item;
    
    //设置图片数据
    cell.image = [UIImage imageNamed:imageName];
    
    return cell;
    
}
@end
